package com.retail.xiaocui.server.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.retail.common.log.annotation.Log;
import com.retail.common.log.enums.BusinessType;
import com.retail.common.security.annotation.RequiresPermissions;
import com.retail.xiaocui.common.domain.Early;
import com.retail.xiaocui.server.service.EarlyService;
import com.retail.common.core.web.controller.BaseController;
import com.retail.common.core.domain.Result;
import com.retail.common.core.utils.poi.ExcelUtil;
import com.retail.common.core.web.page.TableDataInfo;

/**
 * 预警值设置Controller
 *
 * @author retail
 * @date 2024-02-29
 */
@RestController
@RequestMapping("/early")
public class EarlyController extends BaseController
{
    @Autowired
    private EarlyService earlyService;


    /**
     * 查询预警值设置列表
     */
    @RequiresPermissions("xiaocui:early:list")
    @GetMapping("/list")
    public TableDataInfo list(Early early)
    {
        startPage();
        List<Early> list = earlyService.selectEarlyList(early);
        return getDataTable(list);
    }

    /**
     * 导出预警值设置列表
     */
    @RequiresPermissions("xiaocui:early:export")
    @Log(title = "预警值设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Early early) throws IOException, InterruptedException {
        List<Early> list = earlyService.selectEarlyList(early);
        ExcelUtil<Early> util = new ExcelUtil<Early>(Early.class);
        util.exportExcel(response, list, "预警值设置数据");
    }

    /**
     * 获取预警值设置详细信息
     */
    @RequiresPermissions("xiaocui:early:query")
    @GetMapping(value = "/{warningId}")
    public Result getInfo(@PathVariable("warningId") Long warningId)
    {
        return success(earlyService.selectEarlyByWarningId(warningId));
    }

    /**
     * 新增预警值设置
     */
    @RequiresPermissions("xiaocui:early:add")
    @Log(title = "预警值设置", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Early early)
    {
        return toAjax(earlyService.insertEarly(early));
    }

    /**
     * 修改预警值设置
     */
    @RequiresPermissions("xiaocui:early:edit")
    @Log(title = "预警值设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Early early)
    {
        return toAjax(earlyService.updateEarly(early));
    }

    /**
     * 删除预警值设置
     */
    @RequiresPermissions("xiaocui:early:remove")
    @Log(title = "预警值设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{warningIds}")
    public Result remove(@PathVariable Long[] warningIds)
    {
        return toAjax(earlyService.deleteEarlyByWarningIds(warningIds));
    }
}
